package com.gz.tank;

public class Shot implements Runnable {
    private int  x;
    private int y;
    private int direct=0;
    boolean islive=true;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public Shot(int x, int y, int direct) {
        this.direct = direct;
        this.y = y;
        this.x = x;
    }

    private int speed=10;//子弹实际移动速度
    @Override
    public void run(){
        while(true){
            try {
                Thread.sleep(50);//子弹更新速度，越小，子弹看起来越快
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch(direct){
                case 0:
                    y-=speed;
                    break;
                case 1:
                    x+=speed;
                    break;
                case 2:
                    y+=speed;
                    break;
                case 3:
                    x-=speed;
                    break;
            }
            System.out.println("x:"+x+" y:"+y);
            if(!(x>=0 && y>=0 && x<=1000 && y<=750&&islive)){
                islive=false;
                break;
            }
        }
    }
}
